package com.module.app.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.module.base.utils.DisplayUtils;
import com.module.base.R;

/**
 * @author bsnl_yanxuwen
 * @date 2021/4/14 16:19
 * Description :
 */
public abstract class BaseDialog extends Dialog {

    protected ViewGroup rootView;
    private int animResId;//是否启动动画
    private int themeResId;

    public BaseDialog(@NonNull Context context) {
        super(context);
    }

    public BaseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.themeResId = themeResId;
    }

    public abstract int getLayoutId();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rootView = (ViewGroup) getLayoutInflater().inflate(getLayoutId(), null);
        setContentView(rootView);
//        ButterKnife.bind(this, rootView);

        setDialogAttr();

    }

    //底部弹出样式，横向充满
    private void setDialogAttr() {
        Window window = getWindow();
        if (animResId != 0) {
            window.setWindowAnimations(animResId); //设置窗口弹出动画
        }
        window.setBackgroundDrawableResource(R.color.transparent);
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.CENTER;
        params.width = DisplayUtils.getScreenWidth(getContext());
        params.height = DisplayUtils.getScreenHeight(getContext());
        window.setAttributes(params);
        rootView.getChildAt(0).setClickable(true);

    }

    public void setAnimResId(int animResId) {
        this.animResId = animResId;
    }

    public boolean isAnim() {
        return animResId != 0;
    }
}
